'use strict';
const {
    Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
    class Tag extends Model {
        /**
         * Helper method for defining associations.
         * This method is not a part of Sequelize lifecycle.
         * The `models/index` file will call this method automatically.
         */
        static associate(models) {
            // 标签与商品多对多
            models.Tag.belongsToMany(models.Product, {as: 'products', through: "ProductTag", foreignKey: 'tagId'})
        }
    };
    Tag.init({
        name: DataTypes.STRING
    }, {
        sequelize,
        modelName: 'Tag',
    });
    return Tag;
};
